﻿
Imports std
Imports xmlctrl
Imports webctrl
Imports wfileis.data.timeline

Public Class timelinepvp
    Inherits previewPage

    Public Const _pathidentity As String = network.pathSeperator + "t"

    <ThreadStatic()> Private Shared _title As String = Nothing
    <ThreadStatic()> Private Shared _ticks As Int64 = Nothing

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Protected Overrides Function title() As String
        Return _title
    End Function

    Protected Overrides Function startticks() As Int64
        Return _ticks
    End Function

    Protected Overrides Function topics(ByVal start As Int64, ByVal count As Int64) As list(Of String)
        Dim index As recordindex = Nothing
        index = New recordindex()
        If index.read(Nothing, _ticks) AndAlso index.size() > 0 Then
            Dim it As recordindex.iterator = Nothing
            it = index.begin()
            Dim i As Int64
            For i = 0 To start - 1
                it += 1
                If it = index.end() Then
                    Exit For
                End If
            Next
            If i < start Then
                Return Nothing
            Else
                Dim rtn As list(Of String) = Nothing
                rtn = New list(Of String)()
                For i = 0 To count - 1
                    If isemptystring(+it) Then
                        i -= 1
                    Else
                        rtn.push_back(+it)
                    End If
                    it += 1
                    If it = index.end() Then
                        Exit For
                    End If
                Next
                Return rtn
            End If
        Else
            Return Nothing
        End If
    End Function

    Protected Overrides Sub prepare(ByVal context As httpContext)
        MyBase.prepare(context)
        If Not convertor.toint64(strmid(context.url().path(), strlen(pathidentity())), _ticks) Then
            _ticks = index.thismonthtick(Now.Ticks())
        End If
        Dim _d As Date = Nothing
        _d = New Date(_ticks)
        Dim y As String = Nothing
        y = Convert.ToString(_d.Year())
        Dim m As String = Nothing
        m = Convert.ToString(_d.Month())
        Dim d As String = Nothing
        d = Convert.ToString(_d.Day())
        If index.isyeartick(_ticks) Then
            _title = y
        ElseIf index.ismonthtick(_ticks) Then
            _title = y + character.leftSlash + m
        Else
            _title = y + character.leftSlash + m + character.leftSlash + d
        End If
        _title = context.string(stringId.TIMELINE_VIEW_TITLE) + _title
    End Sub
End Class
